package com.tanhua.server.controller;

import com.tanhua.domain.db.UserInfo;
import com.tanhua.server.serivce.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.crypto.interfaces.PBEKey;
import java.io.IOException;

@RestController
@RequestMapping("users")
@Slf4j
public class UserInfoController {

    @Autowired
    private UserService userService;

    /**
     * 接口名称：用户资料 - 读取
     * 接口路径：GET/users
     */
    @GetMapping
    public ResponseEntity<Object> findUserInfoById(){
        log.info("接口名称：用户资料 - 读取");
        return userService.findUserInfoById();
    }

    /**
     * 接口名称：用户资料 - 保存
     * 接口路径：PUT/users
     */
    @PutMapping
    public ResponseEntity<Object> updateUserInfo(
            @RequestBody UserInfo userInfo,
            @RequestHeader("Authorization")String token){
        log.info("接口名称：用户资料 - 保存");
        return userService.updateUserInfo(userInfo,token);
    }

    /**
     * 接口名称：互相喜欢，喜欢，粉丝
     * 接口路径：GET/users/counts
     */
    @GetMapping("counts")
    public ResponseEntity<Object> queryCounts(){
        return userService.queryCounts();
    }

    /**
     * 接口名称：互相喜欢、喜欢、粉丝、谁看过我  (列表)
     * 接口路径：GET/users/friends/:type
     */
    @GetMapping("friends/{type}")
    public ResponseEntity<Object> queryUserLikeList(
            @PathVariable("type") Integer type,
            @RequestParam(defaultValue = "1")Integer page,
            @RequestParam(defaultValue = "10")Integer pagesize){
        return userService.queryUserLikeList(type,page,pagesize);
    }

    /**
     * 接口名称：粉丝 - 喜欢
     * 接口路径：POST/users/fans/:uid
     */
    @PostMapping("fans/{uid}")
    public ResponseEntity<Object> fanLike(@PathVariable("uid") Integer likeUserId){
        return userService.fanLike(likeUserId);
    }
}
